package com.xxcxcxcx.jobsystem.mixin.job.Blacksmith;


import com.xxcxcxcx.jobsystem.Main;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import org.spongepowered.asm.mixin.Mixin;

import static com.xxcxcxcx.jobsystem.common.Job.Blacksmith.Blacksmith.*;

@Mixin(SwordItem.class)
public abstract class ItemStackSwordSpeedMixin extends Item {
    public ItemStackSwordSpeedMixin(Properties p_41383_) {
        super(p_41383_);
    }

    @Override
    public float getDestroySpeed(ItemStack p_43288_, BlockState p_43289_) {
        float num=1.0f;
        CompoundTag compoundTag=p_43288_.getOrCreateTagElement(Main.MOD_ID);
        if(compoundTag.isEmpty()){
            p_43288_.removeTagKey(Main.MOD_ID);
            num = num/10;
        }else{
            if(compoundTag.contains(MakeTool+ToolLevel)){
                num *= num* compoundTag.getFloat(MakeTool+Speed);
            }
        }
        if (p_43289_.is(Blocks.COBWEB)) {
            return 15.0F*num;
        } else {
            Material material = p_43289_.getMaterial();
            return material != Material.PLANT && material != Material.REPLACEABLE_PLANT && !p_43289_.is(BlockTags.LEAVES) && material != Material.VEGETABLE ? 1.0F : 1.5F;
        }
    }

}
